package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("checkGroup")
public class CheckGroupController {
    @Reference
    private CheckGroupService checkGroupService;

    @RequestMapping("add")
    public Result add(@RequestBody CheckGroup checkGroup) {
        return checkGroupService.add(checkGroup);

    }

    @RequestMapping("findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return checkGroupService.pageQuery(queryPageBean);
    }

    @RequestMapping("findById")
    public Result findById(Integer id) {
        return checkGroupService.findById(id);
    }

    @RequestMapping("update")
    public Result update(@RequestBody CheckGroup checkGroup) {
        //交给checkGroupService去处理
        CheckGroup data = (CheckGroup) findById(checkGroup.getId()).getData();
        if ((data.toString()).equals(checkGroup.toString())){
            return Result.success("数据未修改",null);
        }
        return this.checkGroupService.update(checkGroup);
    }

    @RequestMapping("deleteById")
    public Result deleteById(Integer id) {
        return checkGroupService.deleteById(id);
    }

    @RequestMapping("findAll")
    public Result findAll() {
        return checkGroupService.findAll();
    }

}
